package player

import (
	"game/readygo/handler"
	tcsdesign "tcs-server/tcs-design/src"
	"tcs-server/tcs-protobuf/src/tcsprotobuf"

	"google.golang.org/protobuf/reflect/protoreflect"
)

type PlayerCmdMessage struct {
	PlayerContext *PlayerContext
	Wrapper       *tcsprotobuf.MessageWrapper
}

func (m *PlayerCmdMessage) GetPlayerContext() handler.IPlayerContext {
	return m.PlayerContext
}

func (m *PlayerCmdMessage) GetMessageId() int32 {
	return m.Wrapper.Id
}

func (m *PlayerCmdMessage) GetCmd() int32 {
	return m.Wrapper.ProtoId
}

func (m *PlayerCmdMessage) GetData() []byte {
	return m.Wrapper.Data
}

func (m *PlayerCmdMessage) OnException(err error, request protoreflect.ProtoMessage) {
	tips := tcsdesign.TipsOnException(m.Wrapper.ProtoId, request)
	m.PlayerContext.Write(tcsprotobuf.TipsMessage_ID.Number(), tips, m.Wrapper.Id)
}

func (m *PlayerCmdMessage) OnResponse(response interface{}) {
	m.PlayerContext.WriteProto(m.Wrapper.ProtoId, response.(protoreflect.ProtoMessage), m.Wrapper.Id)
}
